package org.ccg

import org.mapdb.DBMaker

object MMKV {
    /**
     * 缓存中写入数据
     */
    fun put(key: String, value: String) {
        DBMaker.fileDB("mydb.db").make().use { db ->
            val map = db.hashMap("myMap")
                .keySerializer(org.mapdb.serializer.SerializerCompressionWrapper(org.mapdb.Serializer.STRING))
                .valueSerializer(org.mapdb.serializer.SerializerCompressionWrapper(org.mapdb.Serializer.STRING))
                .createOrOpen()
            map.put(key, value)
            db.commit()
        }
    }

    /**
     * 缓存中读取 String
     */
    fun getString(key: String): String? {
        return DBMaker.fileDB("mydb.db").make().use { db ->
            val map = db.hashMap("myMap")
                .keySerializer(org.mapdb.serializer.SerializerCompressionWrapper(org.mapdb.Serializer.STRING))
                .valueSerializer(org.mapdb.serializer.SerializerCompressionWrapper(org.mapdb.Serializer.STRING))
                .createOrOpen()
            map[key]
        }
    }
}